<template>
	<Table ref="tableRef" :url="URL_QUERYAFTERSALESLIST" :columns="data.columns" :handles="data.handles"
		:toolbar="data.toolbar" :query="data.query" :params="{ unit: true }" listKey="dataList"></Table>
</template>

<script lang="ts" setup name="afterSalesInfoList">
	import Table from '@/components/table/index.vue';
	import {
		URL_QUERYAFTERSALESLIST,
		deleteAfterSales,
	} from '@/service/apis/user';
	import { exportFile } from '@/utils/utils';
	const router = useRouter();
	const tableRef = ref();
	
	const emit = defineEmits(['get-update']);
	onActivated(() => {
		emit('get-update', (flag : boolean) => {
			if (flag) {
				tableRef.value?.getData();
			}
		});
	});

	const data = reactive({
		columns: [
			{
				prop: 'jobNumber',
				label: '工号',
			},
			{
				prop: 'name',
				label: '姓名',
			},
			{
				prop: 'mobile',
				label: '手机号',
			},
			{
				prop: 'createTime',
				label: '创建时间',
			},
			{
				prop: 'isFrozen',
				label: '状态',
				template: (row : any, index : number) => {
					return row.izUser
						? `<div style="color:#01C68B;">启用</div>`
						: `<div style="color:#FA3939;">禁用</div>`;
				},
			},
			{
				prop: 'remark',
				label: '备注',
			},
		],
		handles: [
			{
				label: '修改',
				permission: 'afterSalesInfoList.edit',
				handle: (row : any) => {
					console.log('编辑---', row);
					router.push({
						name: 'afterSalesInfoEdit',
						query: { id: row.id },
					});
				},
			},
			{
				label: '删除',
				color: '#FA3939',
				permission: 'afterSalesInfoList.delete',
				handle: (row : any) => {
					ElMessageBox.confirm('此操作将永久删除该数据，是否继续？', '提示', {
						confirmButtonText: '确认',
						cancelButtonText: '取消',
						type: 'warning',
					}).then(() => {
						deleteAfterSales({
							id: row.id,
						}).then((res : any) => {
							if (res) {
								tableRef.value.getData();
							}
						});
					});
				},
			},
		],
		toolbar: [
			{
				label: '新增',
				permission: 'afterSalesInfoList.add',
				icon: 'icon-add',
				type: 'primary',
				handle: (row : any) => {
					router.push({
						name: 'afterSalesInfoAdd',
					});
				},
			},
			// {
			// 	label: '导出',
			// 	permission: 'noEnterpriseUserList.export',
			// 	icon: 'icon-export',
			// 	type: 'primary',
			// 	plain: true,
			// 	handle: (row : any) => {
			// 		console.log('导出---', row);
			// 		exportFile(EXPORT_USER, '非企业用户列表', tableRef.value?.getForm());
			// 	},
			// },
		],
		query: [
			{
				label: '姓名',
				prop: 'name',
				comName: 'input',
				props: {
					placeholder: '请输入用户姓名',
				},
			},
			{
				label: '手机号',
				prop: 'mobile',
				comName: 'input',
				props: {
					placeholder: '请输入手机号',
				},
			},
		],
	});
</script>